home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr33 / xcode.zip / XCODE.C < prev    next >
Text File  |  1993-06-26  |  3KB  |  107 lines

  1. /************************************************************************\
  2. **
  3. ** XCODE - File encryption/decryption
  4. ** 06/26/93, John C. Howard @ Compudata BBS, NJ,
  5. ** ref: David Stafford @ ZNT:COMPSHOPPER Compuserv
  6. **
  7. ** Compilation:
  8. ** This code was compiled and tested under Ultrix, Linux, RISC\OS,
  9. ** MS-C for DOS and a few small C compilers without needing any modification.
  10. **
  11. ** Description:
  12. ** The key is a 32 bit value giving 2^32 (4,294,967,296) combinations.
  13. ** If a code breaking program were to process a 1,000 keys a second testing
  14. ** based on an ASCII text file context, decoding would take an average of
  15. ** 25 days.  If two encryption passes are made using 2 keys, that
  16. ** duration would be multiplied by 4 billion.
  17. **
  18. ** Passing the encrypted file back through XCODE with the key will produce
  19. ** the original file.
  20. **
  21. ** Any Suggestions or Comments?  Send me mail at Compudata BBS,
  22. ** (609) 232-1245 on Conference 21 (C-language).
  23. ** 
  24. \************************************************************************/
  25.  
  26. #include <stdio.h>
  27.  
  28.  
  29. /* General definitions */
  30. #define MULTIPLIER    0x015A4E35L
  31. #define INCREMENT    1
  32. #define hlp_msg    "***** XCODE - File encryption/decryption *****\n\nsyntax...  XCODE {key} {in-filename} {out-filename}\n"
  33.  
  34. /* Global vaiables */
  35. static long RandomSeed;
  36. static FILE * infile, * outfile;
  37. static char * infilename, * outfilename;
  38.  
  39.  
  40. /* Close all open files */
  41. void close_all()
  42. {
  43.     fclose( infile );
  44.     fclose( outfile );
  45. }
  46.  
  47. /* Print error message, close all files then exit */
  48. void err_exit( msg )
  49. char * msg;
  50. {
  51.     fprintf( stdout, "\n%s\n", msg );
  52.     close_all();
  53.     exit(-1);
  54. }
  55.  
  56. /* Print help message through error message handler */
  57. void err_help()
  58. {
  59.     err_exit( hlp_msg );
  60. }
  61.  
  62. int GetRandomNumber( range )
  63. int range;
  64. {
  65.     RandomSeed = MULTIPLIER * RandomSeed + INCREMENT;
  66.     return( RandomSeed % range );
  67. }
  68.  
  69. /* Encrypt\Decrypt characters */
  70. void XCODE()
  71. {
  72.     int ch;
  73.  
  74.     while( ( ch = getc( infile ) ) != EOF )
  75.     {
  76.         fputc( ch ^ GetRandomNumber( 256 ), outfile );
  77.     }
  78. }
  79.  
  80. /* Open, encrypt\decrypt then close files */
  81. void Supervisor()
  82. {
  83.     if( NULL == ( infile = fopen( infilename, "rb" ) ) )
  84.         err_exit( "Can't open input file!" );
  85.     if( NULL == ( outfile = fopen( outfilename, "wb" ) ) )
  86.         err_exit( "Can't open output file!" );
  87.  
  88.     XCODE();
  89.  
  90.     close_all();
  91. }
  92.  
  93. void main( argc, argv )
  94. int argc; char * argv[];
  95. {
  96.     if( argc != 4 )
  97.         err_help();
  98.  
  99.     RandomSeed = atol( argv[1] );
  100.     infilename = argv[2];
  101.     outfilename = argv[3];
  102.  
  103.     Supervisor();
  104.  
  105.     exit(0);
  106. }
  107.